/**
 * @param {number[]} milestones
 * @return {number}
 */
 var numberOfWeeks = function(milestones) {
    const n = milestones.length
    if(n === 1){
        return 1
    }
    let ans = 0
    const check = (nums) => {
        let cnt = 0
        for(let i= 0; i<n; i++){
            if(nums[i] > 0){
                cnt++
            }
            if(cnt > 1){
                return true
            }
        }
        return false
    }
    while(check(milestones)){
        milestones.sort((a,b) => b-a)
        ans += 2*milestones[1]
        let flag = (milestones[0] === milestones[1])
        milestones[0] -= milestones[1]
        milestones[1] = 0
        if(flag && milestones[0] > 0){
            milestones[0] -= 1
            ans++
        }
    }
    if(Math.max(...milestones)> 0){
        ans++
    }
    console.log(milestones)
    return ans
};